
<template>
  <div>
    <el-dialog
        title="添加楼栋"
        :visible.sync="dialogVisible"
        width="30%"
    >
  <span> <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="楼栋名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
 <el-form-item label="所属园区">
    <el-select v-model="form.area" placeholder="请选择所属园区">
      <el-option v-for="area in areaList" :key="area.id" :label="area.name" :value="area.id"></el-option>
    </el-select>
  </el-form-item>
          <el-form-item label="楼栋类别">
    <el-select v-model="form.type" placeholder="请选择楼栋类别">
      <el-option label="男" value="男"></el-option>
      <el-option label="女" value="女"></el-option>
    </el-select>
  </el-form-item>
    <el-form-item label="最大层数">
      <el-input v-model.number="form.max_floor"></el-input>
    </el-form-item>
  </el-form></span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import {_buildingAdd, _searchAreaByName} from '../../../../api/super_admin'

export default {
  name: 'BuildingAddDialog',
  created () {
    const DOT = {
      pageSize: 10000,
      pageNo: 1,
      data: {areaName: ''}
    }
    // _areaAll(DOT).then(res => {
    //   console.log('areaAll')
    //   console.log(res)
    //   if (res.status) {
    //     this.areaList = res.data
    //   }
    // })
    _searchAreaByName(DOT).then(res => {
      console.log('areaAll')
      console.log(res)
      if (res.status) {
        this.areaList = res.data
      }
    })
  },
  data () {
    return {
      dialogVisible: false,
      form: {
        name: '',
        max_floor: null,
        type: '',
        area: null
      },
      areaList: [{
        name: '江安小区1',
        address: '川大路1'
      },
      {
        name: '江安小区2',
        address: '川大路2'
      }]
    }
  },
  methods: {
    show () {
      this.dialogVisible = true
    },
    submit () {
      for (let item in this.form) {
        if (item === '') {
          this.$message({
            message: '所有字段非空',
            type: 'error'
          })
          return
        }
      }
      this.$confirm('确定添加楼栋？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const OBJ = JSON.parse(JSON.stringify(this.form))
        OBJ.area = OBJ.area.toString()
        _buildingAdd(OBJ).then(res => {
          if (res.status) {
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.$emit('ok')
            this.dialogVisible = false
          } else {
            this.$message({
              message: '添加失败',
              type: 'warning'
            })
          }
        })
      }).catch()
    }
  }
}
</script>

<style scoped>

</style>
